package com.alawn.system.service.impl;

import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alawn.framework.services.system.DictClassify;
import com.alawn.framework.services.system.Dictionary;
import com.alawn.system.mapper.DictClassifyMapper;
import com.alawn.system.mapper.DictionaryMapper;
import com.alawn.system.service.DictionaryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;

@Service
public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Dictionary> implements DictionaryService {

	@Autowired
	private DictClassifyMapper dictClassifyMapper;

	@Override
	public List<Dictionary> findByClassify(String classifyCode) {
		DictClassify classify = dictClassifyMapper
				.selectOne(new QueryWrapper<DictClassify>().lambda().eq(DictClassify::getCode, classifyCode));
		if (classify != null) {
			return this.list(new QueryWrapper<Dictionary>().lambda().eq(Dictionary::getClassifyId, classify.getId()));
		}
		return Collections.emptyList();
	}

	@Override
	public boolean saveClassify(DictClassify classify) {
		return SqlHelper.retBool(dictClassifyMapper.insert(classify));
	}

	@Override
	public boolean deleteByClassifyId(Long classifyId) {
		return SqlHelper.delBool(dictClassifyMapper.deleteById(classifyId));
	}

	@Override
	public List<DictClassify> listClassify(QueryWrapper<DictClassify> queryWrapper) {
		return dictClassifyMapper.selectList(queryWrapper);
	}

}
